package com.zeus.controller;

import com.zeus.mapper.OrdersMapper;
import com.zeus.pojo.Orders;
import com.zeus.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author 冯扬龙
 * @date 2021/4/22 23:12
 */
@Controller
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/orderList")
    public ModelAndView modelAndView() {
//        查询所有订单信息
        List<Orders> ordersList = ordersService.selectOrderList();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("ordersList", ordersList);
        modelAndView.setViewName("orderList");
        return modelAndView;
    }

    //    管理员点击待发货按钮进入发货界面,通过orderId作为桥梁
    @RequestMapping("/deliverGoods")
    public ModelAndView deliverGoods(int orderId) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("orderId", orderId);
        modelAndView.setViewName("deliverGoods");
        return modelAndView;
    }

    //通过前端传过来的orderId,快递单号，快递信息来修改商品状态，让前台可以看到商品发货了
    @RequestMapping("/submitDeliverGoods")
    public String submitDeliverGoods(int orderId, String shipName, String shipNumber) {
    //        修改订单中的快递信息
        ordersService.updateOrderByShip(orderId, shipName, shipNumber);
    //        跳回订单列表页,要重新走一次/orders/orderList查询更新一下信息，要不然信息不会同步
        return "redirect:/orders/orderList";
    }

}
